<!--#include file="conn.asp"--> 
<!--#include file="bonusAPI.asp"--> 

<% 




'if request.Cookies("hy")("login")="" then
'
'response.Write("{""login"":""no""}")
'Response.End()
'end if




sql="select * from lottery where id="&request("id")
rst.open sql,conn,3,3


if datediff("s",rst("sttime"),now())<0 or datediff("s",rst("endtime"),now())>0 then 
response.Write("{""login"":""ok"",""time"":""no""}")
 Response.End()
end if






'每个ID抽奖次数 

lot_cnum=rst("cnum")



sql="select * from lottery_list where uid='"&myIP&"' and lot_title='"&rst("title")&"' "
rs.open sql,conn,1,1
my_num=rs.recordcount
rs.close

lot_cnum=lot_cnum-my_num






'//获取抽奖参数
lot_title=rst("title")'活动名称
intPercent=rst("jljs")'几率基数
jl=rst("jl")'//各个奖品几率
lot_name=split(rst("name"),",")'奖品名称
lot_num=split(rst("num"),",")'奖品数量
lot_wu=rst("iswu")'无奖品ID
lot_mr=rst("ismr")'默认奖品ID
if isnull(lot_wu) then lot_wu="" 

rst.close





if lot_cnum<=0 then
response.Write("{""login"":""ok"",""num"":0}")

response.End()
end if



'获取抽奖几率

 
strPids ="0|1|2|3|4|5|6|7"
jljs=split(jl,",")
for ji=0 to ubound(jljs)
strProbaly=strProbaly&trim(jljs(ji))&"|"
next
strProbaly=left(strProbaly,len(strProbaly)-1)

set bonus = new BonusAPI
result = bonus.wonAPI(intPercent, strPids, strProbaly)

'如果获奖ID跳空，就默认ID中奖
if result="" then 
result=lot_mr

end if


'如果中奖ID数量为0，就默认ID中奖

if lot_num(result)=0 and instr(lot_wu,result)=0 then
result=lot_mr

end if

'如果中奖ID数量为0，而且默认ID数量为0
'if lot_num(result)=0 and instr(lot_wu,result)=0 and lot_num(lot_mr)=0 then
'result=lot_mr
'
'end if

for ni=0 to 7
if ni=cint(result) then
ni_num=trim(lot_num(ni))-1
else
ni_num=trim(lot_num(ni))
end if
new_num=new_num&","&ni_num

next

new_num=right(new_num,len(new_num)-1)
if instr(lot_wu,result)=0 then
lot_type=1
else
lot_type=0

end if

conn.execute"insert into [lottery_list] (uid,jp,lot_title,type,intime) values ('"&myIP&"','"&lot_name(result)&"','"&lot_title&"',"&lot_type&",'"&now()&"')"


if instr(lot_wu,result)=0 then

conn.execute"update [lottery] set num='"&new_num&"' where id="&request("id")

end if







response.Write("{""login"":""ok"",""num"":"&lot_cnum&",""prize"":"&result&"}")


%>